<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use lxs\api\ApiResponse;
use Throwable;

class Handler extends ExceptionHandler
{
    /**
     * The list of the inputs that are never flashed to the session on validator exceptions.
     *
     * @var array<int, string>
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     */
    public function register(): void
    {
//        $this->reportable(function (Throwable $e) {
//            //
//        });
        $this->renderable(function(Throwable $throwable) {
//            return ApiResponse::apiResponseData(404, '您访问的页面不存在', [
//                'code' => $throwable->getCode(),
//                'message' => $throwable->getMessage(),
//                'file' => $throwable->getFile(),
//                'line' => $throwable->getLine(),
//            ]);

            if(env('APP_DEBUG')) {
                return ApiResponse::apiResponseData(404, '您访问的页面不存在', [
                    'code' => $throwable->getCode(),
                    'message' => $throwable->getMessage(),
                    'file' => $throwable->getFile(),
                    'line' => $throwable->getLine(),
                ]);
            } else {
                return ApiResponse::apiResponseData(404, '您访问的页面不存在');
            }
        });
    }
}
